package com.shushan.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.shushan.base.Constants;
import com.shushan.db.RelaxTimeDao;
import com.shushan.lockscreen.EyeSleepWindowManager;
import com.shushan.lockscreen.LockScreenWindowManager;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.util.ControlUtil;
import com.shushan.util.DateUtils;
import com.shushan.util.SharedPreferencesUtils;


/**
 * @ClassName: SleepFreeReceiver
 * @Desciption: 视力保护解锁广播接收器
 * @author: yichaohua
 * @date: 2018-07-24
 */
public class SleepFreeReceiver extends BroadcastReceiver {

    private static final String TAG = "SleepFreeReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        RelaxTimeDao relaxTimeDao = new RelaxTimeDao(context);
        boolean isContainTime = relaxTimeDao.isContainTime(DateUtils.getHour(),DateUtils.getMinute());
        boolean isContainWeek = relaxTimeDao.isContainWeek();
        Log.i(TAG,"onReceive() isContainTime=" + isContainTime + " isContainWeek=" + isContainWeek);

        int eyeInterval = SharedPreferencesUtils.getIntDate(Constants.PROJECT_EYE_INTERVAL_SHAREPREFERS_KEY);
        ControlUtil.setEyeProjectAlarm(context,eyeInterval);
//
//        if(isContainWeek && isContainTime){
//            return;
//        }else {
            EyeSleepWindowManager.removeEyeFloatWindow(context);
//        }

    }
}
